package com.woniuxy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ManagerController {
    @Autowired(required = false)
    ManagerService managerService;

    @GetMapping("/findManager/{id}")
    public ResponseEntity findRbacManagerById(@PathVariable int id){
        RbacManager rbacManager = managerService.findRbacManagerById(id);
        return new ResponseEntity(200,"查询成功",rbacManager);
    }

    @GetMapping("/findAllManager/{start}/{nums}")
    public ResponseEntity findAllRbacManager(@PathVariable int start, @PathVariable int nums){
        PageHelper.startPage(start,nums);
        List<RbacManager> rbacManagers = managerService.findAllRbacManager();
        PageInfo pageInfo = new PageInfo(rbacManagers);
        return new ResponseEntity(200,"查询成功",pageInfo);
    }
    @PostMapping("/addManager")
    public ResponseEntity add(@RequestBody RbacManager rbacManager){
        int i = managerService.add(rbacManager);
        return new ResponseEntity(200,"添加成功",i);
    }
    @DeleteMapping("/managerDel/{id}")
    public ResponseEntity managerDelete(@PathVariable int id){
        int i = managerService.managerDelete(id);
        return new ResponseEntity(200,"删除成功",i);
    }
    @PutMapping("updateManager")
    public ResponseEntity updateManager(@RequestBody RbacManager rbacManager){
        int i = managerService.updateManager(rbacManager);
        return new ResponseEntity(200,"修改成功",i);
    }
}
